package com.woniu.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    public static final String EXCHANE_TOPIC = "exchange_demo";
    public static final String QUEUE_EMIAL = "queue_demo";
    public static final String ROUTINGKEY_EMAIL = "topic.email";

    // 声明交换机
    @Bean
    public TopicExchange exchange() {
        return new TopicExchange(EXCHANE_TOPIC);
    }

    // 声明队列
    @Bean
    public Queue queue() {
        return new Queue(QUEUE_EMIAL,true);
    }

    // 绑定交换机和队列
    @Bean
    public Binding bindingExchangeMessage() {
        return BindingBuilder.bind(queue()).to(exchange()).with(ROUTINGKEY_EMAIL);
    }
}
